<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>layuiAdmin 后台管理员</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="__STATIC__/layuiadmin/style/admin.css" media="all">
  <style>
    .layui-form-select dl{ max-height: 200px; }
  </style>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">

  <div class="layui-form-item">
    <label class="layui-form-label">目录名称</label>
    <div class="layui-input-inline">
      <input type="text" name="title" lay-verify="required" placeholder="目录名称" autocomplete="off" class="layui-input" value="">

    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">目录名称</label>
    <div class="layui-input-inline">
      <div id="test12" class="demo-tree-more"></div>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">审核状态</label>
    <div class="layui-input-inline">
      <input type="checkbox" lay-filter="switch" name="status" lay-skin="switch" lay-text="使用中|暂停" >
    </div>
  </div>


  <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="LAY-add-role-submit" id="LAY-add-role-submit" value="确认">
  </div>
</div>


 <script src="__STATIC__/layuiadmin/layui/layui.js"></script>
  <script>
  layui.config({
    base: '__STATIC__/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table','tree', 'util'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table
    ,tree = layui.tree
    ,util = layui.util;

    $.ajax({
      type:"POST",
      url:"getMenuTree",
      dataType:"json",
     success:function (res) {
       console.log(res);


       //基本演示
       tree.render({
         elem: '#test12'
         ,data: res
         ,showCheckbox: true  //是否显示复选框
         ,id: 'demoId1'
         ,click: function(obj){
           var data = obj.data;  //获取当前点击的节点数据
           layer.msg('状态：'+ obj.state + '<br>节点数据：' + JSON.stringify(data));
         }
       });

       //获得选中的节点
       // var checkData = tree.getChecked('demoId');

     }
    });

    // var checkData = tree.getChecked('demoId');


    //按钮事件
    util.event('lay-demo', {
      getChecked: function(othis){
        var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据

        layer.alert(JSON.stringify(checkedData), {shade:0});
        console.log(checkedData);
      }
      ,setChecked: function(){
        tree.setChecked('demoId1', [12, 16]); //勾选指定节点
      }
      ,reload: function(){
        //重载实例
        tree.reload('demoId1', {

        });

      }
    });
    












  });
  </script>
</body>
</html>

